package org.grottarossa.ui.core.casemanagement.menu.process;

import org.grottarossa.template.data.pojo.workflows.WorkflowList;
import org.grottarossa.template.drivers.DriverException;
import org.grottarossa.ui.core.ApplicationSession;
import org.grottarossa.ui.core.BPMResource;
import org.grottarossa.ui.core.base.BasePanel;
import org.grottarossa.ui.core.casemanagement.menu.FunctionTreeMenu;
import org.grottarossa.ui.core.container.WorkflowContainer;


import com.vaadin.event.ItemClickEvent.ItemClickListener;
import com.vaadin.ui.Panel;
import com.vaadin.ui.VerticalLayout;
import com.vaadin.ui.Window.Notification;

public class StartableProcessMenuPanel extends BasePanel {


	/**
	 *
	 */
	private static final long serialVersionUID = 4908307567824076738L;

	public StartableProcessMenuPanel(ApplicationSession appSession, String sApp, String sCaption, ItemClickListener itemClickListener)
	{
		super(appSession, null);
		initialize(sApp, sCaption, itemClickListener);
	}

	private void initialize(String sApp, String sCaption, ItemClickListener qml)
	{
		this.setCaption(sCaption);
		this.setIcon(BPMResource.ICON_CASE_TASK);
		this.setScrollable(true);

		VerticalLayout vLayout = new VerticalLayout();
		vLayout.setMargin(false);

		WorkflowList wList;
		try {
			wList = m_appSession.getBuilder().getWorkflowManagement().getWorkflows().getOnlyLatestVersions();
			FunctionTreeMenu services;
			services = new FunctionTreeMenu(m_appSession, qml, sApp, new WorkflowContainer(wList), sCaption);
			vLayout.addComponent(services);
			addComponent(vLayout);
		} catch (DriverException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			getWindow().showNotification(e.getMessage(),Notification.TYPE_ERROR_MESSAGE);
		}

	}

	@Override
	protected void initializeComponents() {
		// TODO Auto-generated method stub

	}
}
